package com.guanyong.admin.controllers.api;

import com.guanyong.admin.handle.GlobleData;
import com.guanyong.model.UserBaseModel;
import com.guanyong.services.UserBaseService;
import com.guanyong.utils.Comm.ResultCode;
import com.guanyong.utils.Comm.ResultObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;

/**
 * Created by mxk on 2017/6/5.
 */
@RestController
@RequestMapping("/api/adminuser/")
public class AdminUserApi {
    @Autowired
    UserBaseService userBaseService;

    @RequestMapping(value = "userlist", method = RequestMethod.GET)
    ResultObject<HashMap<String,Object>> getuserlist(HttpServletRequest request,
                                                     @RequestParam String phone ,
                                                     @RequestParam String username,
                                                     @RequestParam Integer state,
                                                     @RequestParam int pno,
                                                     @RequestParam int pagesize,
                                                     @RequestParam int allcount) {
        ResultObject<HashMap<String,Object>> result = new ResultObject<HashMap<String,Object>>();
        UserBaseModel userBaseModel=new UserBaseModel();
        //只有后台用户
        userBaseModel.setfRegapp(1);
        userBaseModel.setfState(state);
        userBaseModel.setfPhoto(phone);
        userBaseModel.setfUsername(username);
        HashMap<String,Object> hashMap=
                userBaseService.GetUserBaseList(userBaseModel,pno,
                        pagesize,allcount);
        result.setResult(hashMap);
        return result;
    }


    @RequestMapping(value = "useradd", method = RequestMethod.POST)
    ResultObject<Integer> UpdateState(HttpServletRequest request,
                                      @RequestParam String  user_name,
                                      @RequestParam String user_phone,
                                      @RequestParam String user_pwd,
                                      @RequestParam Integer user_role){
        ResultObject<Integer> resultObject=new ResultObject<Integer>();


        return userBaseService.insert(user_name,user_phone,user_pwd,user_role, GlobleData
                .DefaultPhotoPath);


    }



}
